import React,{Component} from "react";
import { withRouter } from 'react-router-dom';

class Header extends Component {
    back = () => {
        this.props.history.goBack()
    }
    forWard = () => {
        this.props.history.goForward(1)
    }
    go = () => {
        this.props.history.go(1)
    }

    render() {
        console.log(this.props)
        return(
            <div style={{height:40,textAlign:'center'}}>
                <h2>React Router Dome</h2>
                <button onClick={this.back}>回退</button>
                <button onClick={this.forWard}>前进</button>
                <button onClick={this.go}>go</button>
            </div>
        )
    }
}
export default withRouter(Header)

// withRouter可以加工一般组件，让一般组件具备路由组件所特有的API（及路由组件的this.props的三个属性值）
//withRouter的返回值是一个新组件